package bbc;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class zky0 {

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int K = Integer.parseInt(bf.readLine());//最大跳数
        int[] arr = new int[K];
        for (int i = 0; i < K; i++) {
            arr[i] = Integer.parseInt(bf.readLine());
        }
        String[] s = bf.readLine().split(" ");
        int N = Integer.parseInt(s[0]);//节点的个数
        int E = Integer.parseInt(s[1]);//边
        int[][] num = new int[E][2];
        for (int i = 0; i < E; i++) {
            String[] s1 = bf.readLine().split(" ");
            num[i][0] = Integer.parseInt(s1[0]);
            num[i][1] = Integer.parseInt(s1[1]);
        }
        //构建一个邻接矩阵
        int [][] res = new int[N][N];
        set(num,res);


        int[] Max = new int[res.length];
        for (int i = 0; i < res.length; i++) {
            int max = 0;
            for (int j = 0; j < res.length; j++) {
                max = Math.max(max,res[i][j]);
            }
            Max[i] = max;
        }

        int result = Max[0];
        for (int i = 0; i < res.length; i++) {
            result = Math.min(result,Max[i]);
        }
        result = arr[result-1];
        System.out.println(result);
    }
    public static void set(int[][] num, int[][] res ){
        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res.length; j++) {
                if(i==j){
                    res[i][i] = 0;
                }else{
                    res[i][j] = Integer.MAX_VALUE;
                }
            }

        }
        for(int[] e:num){
            res[e[0]][e[1]] = res[e[1]][e[0]] = 1;
        }
        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res.length; j++) {
                for (int k = 0; k < res.length; k++) {
                    if(i != k&&j!= k&&res[i][k] != Integer.MAX_VALUE
                    &&res[k][j]!=Integer.MAX_VALUE){
                        res[i][j] = Math.min(res[i][j],res[i][k]+res[k][j]);
                    }
                }
            }
        }
    }
}
